home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / scrasm / page.inc < prev    next >
Text File  |  1993-03-08  |  5KB  |  109 lines

  1. ;; ====================================================================
  2. ;; (Code follows)
  3. ;; ====================================================================
  4.  
  5. EVEN
  6. upper_left      dw      0               ; Stores upper left corner offset
  7.                                         ; relative to page offset.
  8. pages           dw      0               ; for counting frame-per-sec
  9.  
  10. PAGE_INFO       STRUCT 2,NONUNIQUE
  11.                 Address         dw      0
  12.                 UpperLeftAddress dw     0
  13.                 MapPosX         dw      0
  14.                 MapPosY         dw      0
  15.                 Alignment       db      0
  16.                 AlignmentMask   db      0
  17.                 ScrollOffset    dw      0
  18.                 Rectangles      dw      0
  19.                 Valid           db      0
  20. PAGE_INFO       ENDS
  21.  
  22. DrawPage        PAGE_INFO <PAGE_0,PAGE_0>
  23. ShowPage        PAGE_INFO <PAGE_1,PAGE_1>
  24. BlankPage       PAGE_INFO <PAGE_2,PAGE_2>
  25.  
  26. ROTATE3         MACRO   reg,item
  27.                 mov     reg,cs:ShowPage.item
  28.                 xchg    reg,cs:BlankPage.item
  29.                 xchg    reg,cs:DrawPage.item
  30.                 mov     cs:ShowPage.item,reg
  31.                 ENDM    ; Leaves ShowPage.item in reg!
  32.  
  33. ;; This procedure is used to flip between the three available pages.
  34. ;; Originally from Dr. Dobb's Journal's Graphics Programming column by
  35. ;; Michael Abrash, I've reworked the code to be more specific to my
  36. ;; own purposes, and commented it more.
  37. EVEN
  38. FlipPage        PROC    near
  39.         ; This series of instructions circles the show_page, blank_page,
  40.         ; and draw page appropriately and leaves the current page to show
  41.         ; in AX.  Note that it's a lot more instructions than it looks like,
  42.         ; but I unrolled the copy loop for speed.  So-so good idea, because
  43.         ; if you add a field and forget to rotate it, it could mean trouble!
  44.                 ROTATE3 ax,Rectangles
  45.                 ROTATE3 ax,ScrollOffset
  46.                 ROTATE3 ax,MapPosX
  47.                 ROTATE3 ax,MapPosY
  48. ;               ROTATE3 al,AlignmentMask        SPRITES ...
  49.                 ROTATE3 al,Alignment
  50.                 mov     di,ax           ; DI = scroll offset low, and
  51.                                         ; garbage in the high bits...
  52.                 and     di,3            ; DI = pixel pan, 0 to 3.
  53.                 shl     di,1            ; Mode X requires 0 2 4 or 6.
  54.                 ROTATE3 ax,Address
  55.                 ROTATE3 al,Valid
  56.                 ROTATE3 ax,UpperLeftAddress ; Leaves AX=ShowPage.ULAddr
  57.  
  58.                 add     ax,cs:ShowPage.ScrollOffset
  59.  
  60.         ; AX is set up to be the current show page already.
  61.         ; By pre-loading BX with the low-address set code, and CX with
  62.         ; the high-address set code, we can more quickly flip the page
  63.         ; after the vertical retrace period.
  64.                 mov     bl,START_ADDRESS_LOW    ;preload for fastest
  65.                 mov     bh,al                   ; flipping once display
  66.                 mov     cl,START_ADDRESS_HIGH   ; enable is detected
  67.                 mov     ch,ah
  68.  
  69.         ; Wait for display enable to be active (status is active low), to be
  70.         ; sure both halves of the start address will take in the same frame.
  71.                 mov     dx,INPUT_STATUS_1
  72. WaitDE:         in      al,dx
  73.                 test    al,01h
  74.                 jnz     WaitDE  ;display enable is active low (0 = active)
  75.  
  76.         ; Set the start offset in display memory of the page to display.
  77.                 mov     dx,CRTC_INDEX
  78.                 mov     ax,bx
  79.                 out     dx,ax   ;start address low
  80.                 mov     ax,cx
  81.                 out     dx,ax   ;start address high
  82.  
  83.         ; Now wait for vertical sync, so the other page will be invisible when
  84.         ; we start drawing to it.
  85.                 mov     dx,INPUT_STATUS_1
  86. WaitVS:         in      al,dx
  87.                 test    al,08h
  88.                 jz      WaitVS  ;vertical sync is active high (1 = active)
  89.  
  90.         ; Finally, have to adjust the pixel panning register in order
  91.         ; to fine-tune the starting address on a pixel level.
  92.         ; This pixel pan value is the scroll offset mod 4 -- but since
  93.         ; Mode X's pixel pan works by values of 2 (0, 2, 4 or 6) we
  94.         ; have to shift appropriately.
  95.                 mov     dx,ATC_INDEX
  96.                 mov     al,13h  ; 13h = set pixel pan
  97.                 out     dx,al
  98.                 mov     ax,di   ; DI = pixel pan calculated above
  99.                 out     dx,al
  100.                 mov     dx,ATC_INDEX
  101.                 mov     al,32   ; Allows the computer to use this register
  102.                 out     dx,al   ; again.  Without this OUT, the screen will
  103.                                 ; remain blank!
  104.  
  105.         ; Increment the page counter now!
  106.                 inc     cs:pages
  107.                 ret
  108. FlipPage        ENDP
  109.